//
// request_handler.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef HTTP_REQUEST_HANDLER_H
#define HTTP_REQUEST_HANDLER_H

#include <string>
#include "ServerUtil.h" // for checking user valid
#include "MySqlConnector.h" // for calling sql service

namespace http
{
	namespace server
	{
		// Server reply
		struct Reply; 
		// Client request
		struct Request;
		/// The common handler for all incoming requests.
		class RequestHandler
		{
		public:
			RequestHandler(const RequestHandler&) = delete; // no copy constructor 
			RequestHandler& operator=(const RequestHandler&) = delete; // no assignment operator can be used

			/// Construct with a directory containing files to be served.
			explicit RequestHandler(const std::string& doc_root);

			/// Handle a request and produce a reply.
			void handle_request(const Request& req, Reply& rep);

		private:
			/// The directory containing the files to be served.
			std::string doc_root_;
			MySql::MySqlConnector connector; // connector to mysql
			std::shared_ptr<ServerUtil> serverUtil; // util for server


			/// Perform URL-decoding on a string. Returns false if the encoding was
			/// invalid.
			static bool url_decode(const std::string& in, std::string& out);
		};
	} // namespace server
} // namespace http
#endif // HTTP_REQUEST_HANDLER_H